package titt.util.deploy;

import titt.service.content.Mimes;
import titt.util.io.loader.FileStream;

public class FileCache implements Cache {

	private long modifed = -1;
	private byte[] val;
	private final FileStream fl;
	
	public FileCache(FileStream fl) {
		this.fl = fl;
	}
	
	@Override
	public synchronized byte[] getValue() {
		return val;
	}

	@Override
	public synchronized boolean isOutdated() {
		return modifed < fl.lastModified();
	}
	
	@Override
	public String getMimeType() {
		return Mimes.getContentType(fl.getName());
	}
	
	@Override
	public synchronized void update() throws Exception {
		this.modifed = fl.lastModified();
		this.val = fl.readFile();
	}
	
	public String toString() {
		return fl.getName();
	}

}
